package com.ruoyi.loginfo.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loginfo.domain.LogAddress;
import com.ruoyi.loginfo.service.ILogAddressService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物流收货地址Controller
 * 
 * @author ruoyi
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/address")
public class LogAddressController extends BaseController
{
    @Autowired
    private ILogAddressService logAddressService;

    /**
     * 查询物流收货地址列表
     */
    @RequiresPermissions("loginfo:address:list")
    @GetMapping("/list")
    public TableDataInfo list(LogAddress logAddress)
    {
        startPage();
        List<LogAddress> list = logAddressService.selectLogAddressList(logAddress);
        return getDataTable(list);
    }

    /**
     * 导出物流收货地址列表
     */
    @RequiresPermissions("loginfo:address:export")
    @Log(title = "物流收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogAddress logAddress)
    {
        List<LogAddress> list = logAddressService.selectLogAddressList(logAddress);
        ExcelUtil<LogAddress> util = new ExcelUtil<LogAddress>(LogAddress.class);
        util.exportExcel(response, list, "物流收货地址数据");
    }

    /**
     * 获取物流收货地址详细信息
     */
    @RequiresPermissions("loginfo:address:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(logAddressService.selectLogAddressById(id));
    }
    /**
     * 获取物流收货地址详细信息
     */
    @RequiresPermissions("loginfo:address:query")
    @GetMapping(value = "userId/{id}")
    public List<LogAddress> getAddress(@PathVariable("id") Long id)
    {
        System.out.println(id);
        List<LogAddress> logAddresses = logAddressService.getAddress(id);
        return logAddresses;
    }

    /**
     * 新增物流收货地址
     */
    @RequiresPermissions("loginfo:address:add")
    @Log(title = "物流收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogAddress logAddress)
    {
        return toAjax(logAddressService.insertLogAddress(logAddress));
    }

    /**
     * 修改物流收货地址
     */
    @RequiresPermissions("loginfo:address:edit")
    @Log(title = "物流收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogAddress logAddress)
    {
        System.out.println(logAddress);
        return toAjax(logAddressService.updateLogAddress(logAddress));
    }

    /**
     * 删除物流收货地址
     */
    @RequiresPermissions("loginfo:address:remove")
    @Log(title = "物流收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(logAddressService.deleteLogAddressByIds(ids));
    }
}
